import {DELETE_ITEM,HANDLE_PUSH_LIST,CHANGE_INPUT_VALUE} from "./type";

const defaultState={
    inputvalue:'',
    list:[]
}

// reducer可以接受state但是绝对不能够修改state
export default (state=defaultState,action)=>{
    const newstate=JSON.parse(JSON.stringify(state))
    if(action.type==CHANGE_INPUT_VALUE){
        console.log(action.inputvalue)
        newstate.inputvalue=action.inputvalue
        return newstate
    }
    if(action.type==HANDLE_PUSH_LIST){
        newstate.list.push(newstate.inputvalue)
        return newstate
    }
    if(action.type==DELETE_ITEM){
        newstate.list.splice(action.index,1)
        return newstate
    }
    return state
}
